package com.example.demoapachekafka.producer;

import com.alibaba.fastjson2.JSON;
import com.example.demoapachekafka.model.BookInfo;
import org.apache.kafka.clients.producer.ProducerRecord;

public class BookInfoToMessageTransfer {

    private static final String TOPIC = "order-events"; // 指定 Kafka 主题

    public static ProducerRecord<String, String> transfer(BookInfo bookInfo) {
        String key = String.valueOf(bookInfo.getOrderDto().getOrderNo()); // 使用订单号作为键
        String value = JSON.toJSONString(bookInfo); // 将 BookInfo 对象序列化为 JSON 字符串

        return new ProducerRecord<>(TOPIC, key, value);
    }
}
